// 注册页

const userId = require(path.resolve(basename, 'utils/userId.js'));

module.exports = (req, res) => {
    // console.log(req.body);
    // console.log(Date.now(),userId);
    let newUser = new model.User({
        username: req.body.username,
        password: req.body.password,
        createAt: Date.now(),
        userId: userId
    });
    model.User.findOne({
        username: req.body.username
    }).then(result => {
        console.log("查询数据", result);
        if (!result) {
            newUser.save().then(re => {
                console.log("插入数据成功", re);
                res.send({
                    msg: "注册成功",
                    code: "200",
                    status: "405", //405：注册成功；406：注册失败
                })
            });

        } else {
            res.send({
                msg: "注册失败",
                code: "200",
                status: "406", //405：注册成功；406：注册失败
            })
        }
    });
}